Code for opencv text detection from video not working.

by: asmuth444, 8 years ago


I have this code for text detection but it has not been working.

import cv2
import numpy as np
#from pytesser import *

def text_detection():
    cap=cv2.VideoCapture(0)
    cap.open(0)
    while True:
        ret,img=cap.read()
        img2gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
        ret1,mask= cv2.threshold(img2gray,180,255,cv2.THRESH_BINARY)
        image_final=cv2.bitwise_and(img2gray,img2gray,mask=mask)
        ret2,new_img= cv2.threshold(image_final,180,255,cv2.THRESH_BINARY)
        kernel=cv2.getStructuringElement(cv2.MORPH_CROSS,(3,3))
        dilated=cv2.dilate(new_img,kernel,iterations=9)

        idk,contours,hierarchy=cv2.findContours(dilated,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE)
        index =0
        for contour in contours:
            [x,y,w,h]=cv2. boundingRect(contour)

            if w<35 and h<35:
                continue

            cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,255),2)

        cv2.imshow('text_detect',img)
        k=cv2.waitKey(1)& 0xff
        if k==ord('q'):
            break
        cap.release()
        cv2.destroyAllWindows()



text_detection()


and it gives me this error:
Traceback (most recent call last):
  File "C:Python27cvvidcheck.py", line 36, in <module>
    text_detection()
  File "C:Python27cvvidcheck.py", line 10, in text_detection
    img2gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
error: ......opencv-3.1.0modulesimgprocsrccolor.cpp:7456: error: (-215) scn == 3 || scn == 4 in function cv::ipp_cvtColor



You must be logged in to post. Please login or register an account.



That error is jibberish to me, have you tried googling it? Maybe someone else has had this issue before.

-Harrison 8 years ago

You must be logged in to post. Please login or register an account.